package com.iot.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.iot.dao.RedisDao;
import com.iot.domain.Album;
import com.iot.domain.AlbumVo;
import com.iot.domain.MvFile;
import com.iot.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Set;

@Service
public class RedisServiceImpl implements RedisService {


    @Autowired
    private RedisDao redisDao;

    @Override
    public void saveFile(Album album, List<MvFile> files) throws JsonProcessingException {

        //封装相册
        album.setPictures(files);
        //将相册的信息 进行保存
        redisDao.saveFile(album);
    }

    /*返回所有redis  中所有的键*/
    @Override
    public Set<String> findAllPicture() {

     return   redisDao.findAllPicture();
    }

    /*判断相册是否存在*/
    @Override
    public Boolean existAlbum(String albumName) {

        return  redisDao.existAlbum(albumName);
    }

    /*获取指定的相册*/
    @Override
    public Album findPictureByAlbumName(String albumName) throws IOException {


       return redisDao.findPictureByAlbumName(albumName);
    }


    /*获取所有的相册信息*/
    @Override
    public List<AlbumVo> findAllAlbum() throws IOException {

       return redisDao.findAllAlbum();
    }



    /*根据相册的名字上传照片*/
    @Override
    public void uploadPictureByName(String albumName, List<MvFile>  file) throws JsonProcessingException {


        redisDao.uploadPictureByName(albumName,file);

    }


}
